<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
    <%@include file = "init.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/scrip.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />

<title>Insert title here</title>
</head>
<body>
<div class="master-wrapper-content"> 
<jsp:include page="heading.jsp"></jsp:include>
<jsp:include page="listCategory.jsp"></jsp:include>
<div class="container-right">	
	<%
		String username = (String) session.getAttribute("username");
		User user = dataManager.getUserWithUserName(username);
		List<YourCart> ycs = dataManager.getAllCartByUserId(user.getUserId());
		int tongtien = 0;
	%>
	<h2 class="payment_title">Hóa đơn mua hàng</h2>
	<div class="payment">
	
		<p>Thông tin khách hàng</p>
		<table>
			<tr>
				<td>Ten Dang Nhap </td>
				<td>: <%=user.getUsername() %></td>
			</tr>
			<tr>
				<td>Email </td>
				<td>: <%=user.getEmail() %></td>
			</tr>
		</table>
		 
	
	</div>
	<div class="payment">
	<p>Thông tin sản phẩm</p>
	<%
		if(ycs.isEmpty())
		{
			%>
			<h5>Bạn chưa chọn sản phẩm nào</h5>
			<%
		}
		else
		{
			%>
			<table  class="table_product">
		<tr>
			<th>Tên  sản phẩm </th>
			<th>Giá</th>
			<th>Số lượng</th>
			<th>Tổng tiền</th>
		</tr>
		<%
			for(YourCart c : ycs)
			{
				Product p = dataManager.getProductById(c.getProductId());
				tongtien += (c.getNumber()*p.getPrice());
				%>
				<tr>
					<td>
						<p><%=p.getProductName() %></p>
						<img src="<%="/ECommerce/DisplayImage?path=" + p.getImage() %>"/>
					</td>
					<td><%=p.getPrice() %> Dong</td>
					<td><%=c.getNumber() %></td>
					<td><%=c.getNumber()*p.getPrice() %></td>
				</tr>
				<%
			}
		
		%>
	</table>
	</div>
			<%
		}
	%>
	<div class="payment_money">
	<table>
		<tr>
			<td>Tổng số tiền bạn có   </td>
			<td>:  <%=user.getOwnMoney() %></td>
		</tr>
		<tr>
			<td>Tổng tiền sản phẩm   </td>
			<td>:  <%=tongtien %></td>
		</tr>
		<tr>
			<td>Phí vận chuyển   </td>
			<td>: Khách hàng tự trả</td>
		</tr>
		
	</table>
	</div>
	<%
	if(user.getOwnMoney()>=tongtien && !ycs.isEmpty())
	{
		%>
		<form action="payment" method="get" class="payment_form">
			<input type="hidden" name="userId" value="<%=user.getUserId()%>"/>
			<input type="hidden" name="tongtien" value="<%=tongtien%>"/>
			<input type="submit" value="Thanh Toan" onclick="paymentSuccess()"/>
		</form>
		
		<%
		
	}
	else{
		%>
		<p style="color: red;">Không có tiền mà cũng đòi đi mua hàng, nộp thẻ đi thằng khốn</p>
		<%
	}
	%>
	
	</div>
	<div class="clear"></div>
	</div>
	
</body>
</html>